<template>
  <div>
    <div class="nav-bar-container">
      <div class="left-action-bar">
        <img src="@/assets/logo-gray-light.png" class="icon" />
      </div>
      <el-menu
        :default-active="activeIndex"
        mode="horizontal"
        :router="true"
        style="max-width: 600px"
        class="nav-bar"
        text-color="#CCCCCC"
        background-color="#292A2D"
        active-text-color="#FFFFFF"
        :ellipsis="false"
      >
        <el-menu-item index="/">凤凰书社</el-menu-item>
        <el-menu-item index="/cart">购物车</el-menu-item>
        <el-menu-item index="/warehouse" :disabled="!isAdministrator">商品库存</el-menu-item>
        <el-menu-item index="/comment">留言板</el-menu-item>
      </el-menu>
      <div class="right-action-bar">
        <div class="right-action">
          <UserInformation />
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import UserInformation from './UserInformation.vue'
import { useUserStore } from '@/stores/user.js'
import { ref } from 'vue'

const user = useUserStore();

const activeIndex = ref('/')

const isAdministrator = user.isAdministrator
</script>

<style scoped>
.icon {
  height: 40px;
  padding: 7px 0 0 20px;
  cursor: pointer;
}

.nav-bar-container {
  display: flex;
  justify-content: space-between; /* 左右元素贴边 */
  align-items: center;
  background-color: #292A2D;
  text-align: center;
  height: 60px;
}

.nav-bar {
  flex: 0; /* 占据剩余空间 */
  display: flex;
  justify-content: center; /* 中间3个元素水平居中 */
  /*  gap: 20px; 元素间距 */
}

.left-action-bar, .right-action-bar  {
  flex: 0 0 auto;
  height: 100%;
}


.right-action {
  padding: 14px 15px;
}

.right-action > i {
  margin-right: 10px;
  color: #ccc;
  font-size: 20px;
  line-height: 60px;
}

.right-action > i:hover {
  color: #fff;
}

a {
  color: rgb(204, 204, 204);
  text-decoration: none;
}
</style>
